<template>
  <div id="app">
    <!-- 顶部导航 -->
    <Topbar :key="topbarKey"></Topbar>
    <!-- 头部nav链接 -->
    <Header></Header>
    <!-- 路由出口  就是home  可以写中间的部分渲染 -->
    <router-view @updateKey="updateKeyFn" />

    <Footer></Footer>
    <Login v-show="isShowLoginModal"></Login>
    <transition>
      <Toast v-show="isShowToast"> </Toast>
    </transition>
  </div>
</template>
<script>
import Topbar from "./components/Topbar.vue";
import Header from "./components/Header.vue";
import Footer from "./components/Footer.vue";
import Login from "./components/Login.vue";
import Toast from "./components/Toast.vue";
// import request from "./request/request";
import { JingPinAPI } from "./request/api";
import { mapState } from "vuex";
export default {
  data() {
    return {
      topbarKey: 1,
    };
  },
  components: {
    Topbar,
    Header,
    Footer,
    Login,
    Toast,
  },
  computed: {
    ...mapState({
      isShowLoginModal: (state) => state.showModal.isShowLoginModal,
      // icon组件的封装isShowToast
      isShowToast: (state) => state.showToast.isShowToast,
    }),
  },
  //   async created() {
  //     let res = await JingPinAPI();
  //     console.log("res", res);
  //   },
  methods: {
    updateKeyFn() {
      this.topbarKey++;
    },
  },
  watch: {
    "$route.path": {
      handler(newVal, oldVal) {
        //   console.log("ap-watch");
        this.topbarKey++;
      },
    },
  },
};
</script>

<style lang="less">
/* 入场的起始状态 = 离场的结束状态 */
.slide-enter,
.slide-leave-to {
  opacity: 0;
}

.slide-enter-active,
.slide-leave-active {
  transition: opacity 0.3s linear;
}

.slide-enter-to,
.slide-leave {
  opacity: 1;
}
</style>
